package org.example.jiap.bk.service.Impl;

import org.example.jiap.bk.mapper.JiapUserMapper;
import org.example.jiap.bk.model.pojo.JiapUserPOJO;
import org.example.jiap.bk.service.JiapUserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class JiapUserServiceImpl implements JiapUserService {
    @Resource
    private JiapUserMapper jiapUserMapper;

    @Override
    public int register(JiapUserPOJO userPOJO) {

        //前端->Crontroller->Service->mapper里透传来userPOJO,用它的Account再去做查询
        JiapUserPOJO wkExitUserPOJO = jiapUserMapper.user_select_account(userPOJO.getAccount());

        //查询结果返回一个UserPOJO对象
        if (wkExitUserPOJO == null) {
            jiapUserMapper.user_insert(userPOJO);
            System.out.println("用户注册成功");
            return 0;
        } else {
            //return ResultPOJO.error("用户已存在");
            System.out.println("用户已存在");
            return -1;
        }

    }

    @Override
    public void login(JiapUserPOJO userPOJO) {

        //前端->Crontroller->Service->mapper里透传来userPOJO,用它的Account再去做查询
        JiapUserPOJO seExitUserPOJO = jiapUserMapper.user_select_accpwd(userPOJO.getAccount(), userPOJO.getPassword());
        if (seExitUserPOJO != null) {
            System.out.println("用户登录成功");
        } else {
            System.out.println("用户密码错误");
        }
    }

    @Override
    public void refresh(JiapUserPOJO userPOJO) {
        jiapUserMapper.user_update(userPOJO);
        System.out.println("更新成功");
    }

    @Override
    public void querry(JiapUserPOJO userPOJO) {
        List<JiapUserPOJO> lst = jiapUserMapper.user_selectalluser(userPOJO.getCreateUser());

        for (int i = 0; i < lst.size(); i++) {
            System.out.println(lst.get(i).getAccount() + lst.get(i).getPassword() + lst.get(i).getCreateUser());
        }

        System.out.println("查询成功");
    }

    @Override
    public void querrymix(JiapUserPOJO userPOJO) {
        List<JiapUserPOJO> lst = jiapUserMapper.user_selectmix(userPOJO.getPthone(),userPOJO.getUserName(),userPOJO.getAccount(),userPOJO.getCreateTime());

        for (int i = 0; i < lst.size(); i++) {
            System.out.println(lst.get(i).getAccount() + lst.get(i).getPassword() + lst.get(i).getCreateUser());
        }

        System.out.println("查询成功5");
    }

}
